package com.whmskj.xjlhbc.mobile.controller;

import com.whmskj.xjlhbc.core.AjaxResult;
import com.whmskj.xjlhbc.dto.EnergyConsumption.WorkShopEnergyGroupDto;
import com.whmskj.xjlhbc.dto.EnergyConsumption.WorkShopEnergySummaryVo;
import com.whmskj.xjlhbc.dto.EnergyConsumption.WorkshopEnergyResponse;
import com.whmskj.xjlhbc.service.EnergyConsumptionService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @Author: Sakura
 * @Date: 2025/8/21 10:32
 * @Version: v1.0.0
 * @Description: TODO
 **/

/**
 * @Author: Sakura
 * @Date: 2025/8/21 10:32
 * @Version: v1.0.0
 * @Description: 车间能耗统计接口
 **/
@RestController
@Tag(name = "车间能耗", description = "车间能耗")
@RequestMapping("/energy/workshop")
public class EnergyConsumptionController {

    @Autowired
    private EnergyConsumptionService energyService;

    /**
     * 统计车间能耗数据
     * @param startDate 开始日期
     * @param endDate 结束日期
     * @param workshop 车间名称
     * @return 能耗统计数据
     */
    @GetMapping("/summary")
    public AjaxResult getEnergySummary(@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
                                       @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
                                       @RequestParam(required = false) String workshop) {
            WorkShopEnergySummaryVo summary = energyService.getWorkshopEnergySummary(startDate, endDate, workshop);
            return AjaxResult.success(summary);
    }

    /**
     * 获取车间能耗详情
     * @param workshop 车间名称
     * @return 车间能耗详情
     */
    @GetMapping("/details")
    public AjaxResult getEnergyDetails(@RequestParam String workshop,
                                       @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date queryDate) {
        try {
            WorkshopEnergyResponse result = energyService.getEnergyDetailsByWorkshopAndDate(workshop, queryDate);
            return AjaxResult.success(result);
        } catch (Exception e) {
            return AjaxResult.error("查询车间能耗详情失败: " + e.getMessage());
        }
    }


}